<template>
	<view class="page">
		<kefu :qq="parseInt(gConfig.common_app_customer_service_tel)" v-if="gConfig.common_app_is_online_service=='1'"></kefu>
		<!-- search -->
		<!-- #ifdef MP -->
		<view class="mp-search-box">
			<input class="ser-input" type="text" value="输入关键字搜索" confirm-type="search" @confirm="search"/>
		</view>
		<!-- #endif -->
		<!-- banner -->
		<view class="indexbanner" :style="{backgroundColor:titleNViewBackground}">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular @change="swiperChange"
			 class="banner">
				<swiper-item v-for="(item,index) in bannerList" :key="index">
					<image :src="item.images_url" class="banner"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 首页导航 -->
		<view class="nav">
			<scroll-view scroll-x="true">
				<view class="item" v-for="item in navigation" :key="item.id" @tap="navTo(item.event_value)">
					<image :src="item.images_url" class="img"></image>
					<view class="title ellipsis">{{item.name}}</view>

				</view>
			</scroll-view>
		</view>
		<!-- 广告1 -->
		<view class="ad1">
			<image :src="item.images_url" v-for="item in adList" :key="item.id" mode="aspectFit"></image>
		</view>
		<!-- 分类推荐楼层-->
		<view class="pro">
			<view class="floor" v-for="(item,index) in indexData" :key="index">
				<view class="f-header m-t">
					<image :src="item.icon"></image>
					<view class="tit-box">
						<text class="tit">{{item.name}}</text>
						<text class="tit2">{{item.vice_name}}</text>
					</view>
					<text class="iconfont icon-jiantouarrow487" @tap="navTo('/pages/product/list?fid='+item.id)"></text>
				</view>
				<view class="hot-floor">
					<view class="floor-img-box">
						<image class="floor-img" :src="item.big_images"
						 mode="scaleToFill"></image>
					</view>
					<scroll-view class="floor-list" scroll-x>
						<view class="scoll-wrapper">
							<view v-for="(item1, index1) in item.goods" :key="index1" class="floor-item" @click="navTo('/pages/product/product?id='+item1.id)">
								<image :src="item1.home_recommended_images" mode="aspectFill"></image>
								<text class="title clamp ellipsis">{{item1.title}}</text>
								<text class="price ellipsis">￥{{item1.price}}</text>
							</view>
							<view class="more" @tap="navTo('/pages/product/list?fid='+item.id + '&sid=' + item['items'][0]['id'] + '&tid=' + item['items'][0]['items'][0]['id'])">
								<text>查看全部</text>
								<text>More+</text>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
		
		<!-- 猜你喜欢 -->
		<view class="guess">
			<view class="f-header m-t">
				<image src="/static/icon/h1.png"></image>
				<view class="tit-box">
					<text class="tit">猜你喜欢</text>
					<text class="tit2">Guess You Like It</text>
				</view>
			</view>
			
			<view class="guess-section">
				<view 
					v-for="(item, index) in likeData" :key="index"
					class="guess-item"
					@click="navTo('/pages/product/product?id=' + item.id)"
				>
					<view class="image-wrapper">
						<image :src="item.images" mode="aspectFill"></image>
					</view>
					<text class="title clamp ellipsis">{{item.title}}</text>
					<text class="price ellipsis">￥{{item.price}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import kefu from '@/components/yu-kefu.vue'
	export default {
		components:{
			kefu
		},
		data() {
			return {
				gConfig:[],
				bannerList: [],
				titleNViewBackground: '#fa436a',
				swiperCurrent: 0,
				navigation: [],
				adList: [],
				indexData:[],
				likeData:[],
				userInfo:[]
			}
		},
		onLoad() {
			// 取出全局配置信息
			this.bannerList = uni.getStorageSync("iBanner");
			this.navigation = uni.getStorageSync('navigation');
			this.adList = uni.getStorageSync('adList');
			this.indexData=uni.getStorageSync('indexData');
			this.gConfig=uni.getStorageSync('gConfig');
		},
		onShow(){
			this.userInfo=uni.getStorageSync('gUserInfo');
			this.likeData=uni.getStorageSync('likeData');
		},
		methods: {
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
				this.titleNViewBackground = this.bannerList[index].bg_color;
			},
			navTo(url) {
				uni.navigateTo({
					url
				})
				
			},
			// #ifdef MP
			search(e){
				let keywords=e.detail.value;
				uni.navigateTo({
					url: `/pages/product/search?keywords=${keywords}`
				});
			},
			// #endif
			
			// #ifndef MP
			//触发搜索
			onNavigationBarSearchInputConfirmed(e){
				let keywords=e.text;
				uni.navigateTo({
					url: `/pages/product/search?keywords=${keywords}`
				});
			},
			//点击导航栏 buttons 时触发
			onNavigationBarButtonTap(e) {
				// 把对象 this.userInfo  转成数组
				let arr=Object.getOwnPropertyNames(this.userInfo);
				const index = e.index;
				if (index === 0) {
					if(arr.length>0){
						uni.switchTab({
							url:'/pages/member/member'
						})
					}else{
						uni.navigateTo({
							url:'/pages/member/login'
						})
					}
				} else if (index === 1) {
					uni.navigateTo({
						url: '/pages/article/list?cid=25'
					})
				}
			}
			// #endif
		},
		watch: {
			adList: function() {
				for (let index in this.adList) {
					this.adList[index]['images_url'] = this.util.get_img_url(this.adList[index]['images_url']);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifdef MP */
	.mp-search-box{
		position:absolute;
		left: 0;
		top: 15upx;
		z-index: 9999;
		width: 100%;
		padding: 0 80upx;
		.ser-input{
			flex:1;
			height: 56upx;
			line-height: 56upx;
			text-align: center;
			font-size: 28upx;
			color:$uni-text-color;
			border-radius: 20px;
			background: rgba(255,255,255,.6);
		}
	}
	page{
		.cate-section{
			position:relative;
			z-index:5;
			border-radius:16upx 16upx 0 0;
			margin-top:-20upx;
		}
		.carousel-section{
			padding: 0;
			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}
			.carousel{
				.carousel-item{
					padding: 0;
				}
			}
			.swiper-dots{
				left:45upx;
				bottom:40upx;
			}
		}
	}

	/* #endif */
	
	// 首页banner

	.indexbanner {
		padding: 80rpx 30rpx 0;
		height: 420rpx;
	}

	

	.banner {
		width: 100%;
		height: 370rpx;
		border-radius: $uni-border-radius-lg;
	}

	// 首页导航
	.nav {
		width: 100%;
		padding: 60rpx 30rpx;
		height: 210rpx;
		white-space: nowrap;
		box-sizing: border-box;
	}

	.nav .item {
		width: 20%;
		text-align: center;
		display: inline-block;
	}

	.nav .item .img {
		border-radius: $uni-border-radius-circle;
		width: 96rpx;
		height: 96rpx;
	}

	.nav .item .title {
		font-size: $uni-font-size-sm;
	}

	// ad1
	.ad1 {
		width: 100%;
		text-align: center;
		box-sizing: border-box;
	}

	.ad1 image {
		width: 100%;
		height: 240rpx;
	}

	// 楼层样式
	.floor{width:100%;overflow: hidden;padding:30rpx 0 0 0;background: $uni-bg-color-grey;}
	.f-header {
		display: flex;
		align-items: center;
		height: 140upx;
		padding: 6upx 30upx 8upx;
		background: $uni-bg-color;

		image {
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			margin-right: 20upx;
		}

		.tit-box {
			flex: 1;
			display: flex;
			flex-direction: column;
		}

		.tit {
			font-size: $uni-font-size-lg;
			color: $uni-text-color;
			line-height: 1.3;
		}

		.tit2 {
			font-size: $uni-font-size-sm;
			color: $uni-text-color;
		}

		.icon-jiantouarrow487 {
			font-size: $uni-font-size-lg+8upx;
			color: $uni-text-color-zhu;
		}
	}

	/* 分类推荐楼层 */
	.hot-floor {
		width: 100%;
		overflow: hidden;

		.floor-img-box {
			width: 100%;
			height: 320upx;
			position: relative;

			&:after {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				background: linear-gradient(rgba(255, 255, 255, .06) 30%, #f8f8f8);
			}
		}

		.floor-img {
			width: 100%;
			height: 100%;
		}

		.floor-list {
			white-space: nowrap;
			padding: 20upx;
			border-radius: 6upx;
			margin-top: -140upx;
			margin-left: 30upx;
			background: #fff;
			box-shadow: 1px 1px 5px rgba(0, 0, 0, .2);
			position: relative;
			z-index: 1;
			width:690rpx;
			box-sizing: border-box;
		}

		.scoll-wrapper {
			display: flex;
			align-items: flex-start;
		}

		.floor-item {
			width: 180upx;
			margin-right: 20upx;
			font-size: $uni-font-size-sm;
			color: $uni-text-color;
			line-height: 1.8;
			display: flex;
			flex-direction: column;
			image {
				width: 180upx;
				height: 180upx;
				border-radius: 6upx;
				border:solid 1px $uni-border-color;
			}

			.price {
				color: $uni-text-color-zhu;
			}
		}

		.more {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			flex-shrink: 0;
			width: 180upx;
			height: 180upx;
			border-radius: 6upx;
			background: #f3f3f3;
			font-size: $uni-font-size-base;
			color: $uni-text-color;

			text:first-child {
				margin-bottom: 4upx;
			}
		}
	}
	
	/* 猜你喜欢 */
	.guess-section{
		display:flex;
		flex-wrap:wrap;
		padding: 0 30upx;
		background:$uni-bg-color;
		.guess-item{
			display:flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;
			&:nth-child(2n+1){
				margin-right: 4%;
			}
		}
		.image-wrapper{
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;
			border:solid 1px $uni-border-color;
			image{
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.title{
			font-size: $uni-font-size-sm;
			color: $uni-text-color;
			line-height: 80upx;
		}
		.price{
			font-size:$uni-font-size-lg;
			color: $uni-text-color-zhu;
			line-height: 1;
		}
	}
</style>
